<template>
	<view>
		<cmd-cel-item title="人员名称" :addon="userInfo['人员名称']"></cmd-cel-item>
		<cmd-cel-item title="联系方式" :addon="userInfo['手机号']"></cmd-cel-item>
		<cmd-cel-item title="证件号码" :addon="userInfo['身份证']"></cmd-cel-item>
		<cmd-cel-item title="工作时段" :addon="workTime"></cmd-cel-item>
		<cmd-cel-item title="工作日" :addon="currentInfo.工单员.工作日 | formatDay"></cmd-cel-item>
		<cmd-cel-item title="休息时间是否派单" @click="handleTap('picker')" :addon="label" arrow></cmd-cel-item>
		<lb-picker ref="picker" mode="selector" :list="chooseList" :dataset="{ name: 'label' }" @change="handleChange"
			@confirm="handleConfirm" @cancel="handleCancel">
		</lb-picker>
	</view>
</template>

<script>
	import LbPicker from "@/components/lb-picker";
	import cmdCelItem from "@/myComponents/cmd-cell-item/cmd-cell-item.vue"
	export default {
		components: {
			cmdCelItem,
			LbPicker
		},
		data() {
			return {
				label: '',
				value: null,
				chooseList: this.$type.chooseList,
				dateType: this.$type.dateType,
				status: {
					1: '是',
					2: '否'
				},
				active: 0,
				data: 132,
				userInfo: {},
				currentInfo: {},
				currentUnitId: null,
				workTime: ''
			}
		},
		onLoad() {
			this.userInfo = JSON.parse(JSON.stringify(uni.getStorageSync('userInfo')))
			this.currentUnitId = uni.getStorageSync('currentUnitId')
			this.currentInfo = this.userInfo.单位.find(item => item.单位id === this.currentUnitId)
			this.workTime = this.currentInfo.工单员.工作时段开始 + '-' + this.currentInfo.工单员.工作时段结束
			// this.operatorDetail = JSON.parse(JSON.stringify(res.data))
			this.currentInfo.工单员.工作日.sort()
			this.currentInfo.工单员.工作日 = this.currentInfo.工单员.工作日 && this.currentInfo.工单员.工作日.map(item => this.dateType[
				item])
			this.label = this.status[this.currentInfo['工单员']['休息时间是否派单']]
		},
		methods: {
			handleTap(name) {
				this.$refs[name].show()
			},
			handleChange(e) {
				console.log('change::', e)
			},
			handleConfirm(e) {
				// 如果存在多个picker，可以在picker上设置dataset属性，confirm中获取，就能区分是哪个picker了
				console.log('confirm::', e)
				if (e) {
					const name = e.dataset.name
					const label = e.item.label

					let newInfo = uni.getStorageSync('userInfo')
					let currentInfo = newInfo.单位.find(item => item.单位id === this.currentUnitId)
					currentInfo.工单员.休息时间是否派单 = e.item.id
					this.value = e.item.id
					// delete currentInfo.工单员.id
					// console.log(this.userInfo)
					let params = {
						id: newInfo.id,
						所属单位: uni.getStorageSync('currentUnitId'),
						人员名称: newInfo.人员名称,
						手机号: newInfo.手机号,
						身份证: newInfo.身份证,
						工单员: currentInfo.工单员
					}

					this.editUserInfo(params)
					if (name && label) {
						this[name] = label
					}
				}
			},
			editUserInfo(params) {
				this.$http2.post('worksys/worker/update', params).then(res => {
					if (res.code === 10000) {
						uni.showToast({
							title: '修改成功'
						})
						let userInfo = uni.getStorageSync('userInfo')
						let currentInfo = userInfo.单位.find(item => item.单位id === this.currentUnitId)
						currentInfo.工单员.休息时间是否派单 = this.value
						uni.setStorageSync('userInfo', userInfo)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
</style>
